package com.hyt.it.ogt.kq.main.controller.bm;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.kq.common.bm.utils.Constant;
import com.hyt.it.ogt.kq.main.controller.base.BaseController;
import com.hyt.it.ogt.kq.service.bm.model.entity.TextBookBuyRecord;
import com.hyt.it.ogt.kq.service.bm.model.entity.TextBookInfo;
import com.hyt.it.ogt.kq.service.bm.model.entity.TextBookStudent;
import com.hyt.it.ogt.kq.service.bm.model.entity.TextBookTotal;
import com.hyt.it.ogt.kq.service.bm.model.vo.TextBookBuyRecordsQueryVo;
import com.hyt.it.ogt.kq.service.bm.model.vo.TextBookList;
import com.hyt.it.ogt.kq.service.bm.model.vo.TextBookPayList;
import com.hyt.it.ogt.kq.service.bm.model.vo.TextBookSet;
import com.hyt.it.ogt.kq.service.bm.service.TextBookService;
import com.hyt.model.PageParam;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;

/**
 * 教材管理模块
 * 
 * @author wangt
 * @Description:
 * @date: 2020年9月1日 上午10:39:18
 * @version: V1.0
 */
@RestController
@Api(tags = "17.教材管理模块接口", value = "教材管理模块接口")
@ApiSort(value = 17)
@RequestMapping("/bm/textBook")
public class TextBookController extends BaseController {

	@Autowired
	private TextBookService textBookService;

	/**
	 * 任务购买教材数量统计
	 * @param pageParam 分页参数
	 * @return
	 */
	@ApiOperation(value = "17.1.1 教材管理：任务购买教材数量统计(报名任务列表)", notes = "20000:成功")
	@ApiOperationSort(value = 1)
	@RequestMapping(value = "/textBookTotal", method = RequestMethod.GET)
	public Object textBookTotal(PageParam<TextBookTotal> pageParam) {
		IPage<TextBookTotal> page = pageParam;
		//获取顶级机构ID
		String officeId = this.getOfficeId();
		page = textBookService.textBookTotal(pageParam, officeId);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(page).build();
	}

	/**
	 * 查看任务的购买情况统计
	 * @param projcetId 报名任务ID
	 * @return
	 */
	@ApiOperation(value = "17.1.2 教材管理： 查看任务的购买情况统计", notes = "20000:成功")
	@ApiOperationSort(value = 2)
	@RequestMapping(value = "/totalBooksPayList", method = RequestMethod.GET)
	public Object totalBooksPayList(String projcetId) {
		List<TextBookPayList> list = textBookService.totalBooksPayList(projcetId);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(list).build();
	}

	/**
	 * 教材购买-任务下，考生的详细购买情况列表
	 * 
	 * @param param
	 * @param pageParam
	 * @return
	 */
	@ApiOperation(value = "17.1.3 教材管理： 任务下，考生的详细购买情况列表", notes = "20000:成功")
	@ApiOperationSort(value = 3)
	@RequestMapping(value = "/payUnderTask", method = RequestMethod.GET)
	public Object payUnderTask(TextBookBuyRecordsQueryVo textBookBuyRecordsQueryVo, PageParam<TextBookBuyRecord> pageParam) {
		IPage<TextBookBuyRecord> page = pageParam;
		page = textBookService.findPayStuPageBook(pageParam, textBookBuyRecordsQueryVo);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(page).build();
	}

	@ApiOperation(value = "17.1.4 教材管理：教材购买-任务下 - 开发票", notes = "20000:成功")
	@ApiOperationSort(value = 4)
	@RequestMapping(value = "textBookInvoice", method = RequestMethod.GET)
	public Object textBookInvoice(String orderId) {
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(null).build();
	}

	@ApiOperation(value = "17.1.5 教材管理： 查询考生购买的教材详情", notes = "20000:成功")
	@ApiOperationSort(value = 5)
	@RequestMapping(value = "/getStuBookList", method = RequestMethod.GET)
	public Object getStuBookList(String orderId) {
		List<TextBookTotal> list = textBookService.getStuBookList(orderId);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(list).build();
	}

	@ApiOperation(value = "17.1.6 教材管理： 导出教材列表", notes = "20000:成功")
	@ApiOperationSort(value = 6)
	@RequestMapping(value = "/exportBooksList", method = RequestMethod.GET)
	public void exportBooksList(TextBookStudent textBookParam, HttpServletResponse response) {
		try {
			textBookService.exportBooksList(response, textBookParam);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@ApiOperation(value = "17.1.7 教材管理：教材设置-任务列表", notes = "20000:成功")
	@ApiOperationSort(value = 7)
	@RequestMapping(value = "/textBookTaskList", method = RequestMethod.GET)
	public Object textBookTaskList(String projectName, PageParam<TextBookList> pageParam) {
		IPage<TextBookList> page = pageParam;
		page = textBookService.textBookList(pageParam, projectName);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(page).build();
	}

	@ApiOperation(value = "17.1.8 教材管理： 查询教材设置配置（限制购买设置）", notes = "20000:成功")
	@ApiOperationSort(value = 8)
	@RequestMapping(value = "/textBookFormSet", method = RequestMethod.GET)
	public Object textBookFormSet(String projectId) {
		TextBookSet textBookSet = textBookService.textBookFormSet(projectId);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(textBookSet).build();
	}

	@ApiOperation(value = "17.1.9 教材管理： 教材设置参数保存 ", notes = "20000:成功")
	@ApiOperationSort(value = 9)
	@RequestMapping(value = "/textBookFormSetSave", method = RequestMethod.POST)
	public Object textBookFormSetSave(@RequestBody TextBookSet textBookSet) {
		int count = textBookService.textBookFormSetSave(textBookSet);
		if (count > 0) {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data("教材设置保存成功！").build();
		} else {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_31010189).data("教材设置保存失败！").build();
		}
	}

	@ApiOperation(value = "17.1.10  教材管理： 查询教材列表", notes = "20000:成功")
	@ApiOperationSort(value = 10)
	@RequestMapping(value = "/bookList", method = RequestMethod.GET)
	public Object bookList(String projectId, PageParam<TextBookInfo> pageParam) {
		IPage<TextBookInfo> page = pageParam;
		page = textBookService.bookList(pageParam, projectId);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(page).build();
	}

	@ApiOperation(value = "17.1.11 教材管理： 教材添加、修改 ", notes = "20000:成功")
	@ApiOperationSort(value = 11)
	@RequestMapping(value = "/textBookSave", method = RequestMethod.POST)
	public Object textBookSave(@RequestBody TextBookInfo textBookInfo) {
		int count = textBookService.textBookSave(textBookInfo);
		if (count > 0) {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data("教材保存成功！").build();
		} else {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_31010189).data("教材保存失败！").build();
		}
	}

	@ApiOperation(value = "17.1.12 教材管理： 删除教材 ", notes = "20000:成功")
	@ApiOperationSort(value = 12)
	@RequestMapping(value = "/delteTextBook", method = RequestMethod.GET)
	public Object delteTextBook(String id) {
		int count = textBookService.delteTextBook(id);
		if (count > 0) {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data("教材删除成功！").build();
		} else {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_31010190).data("教材删除失败！").build();
		}
	}

	@ApiOperation(value = "17.1.13 教材管理：查询历史复用信息 ", notes = "20000:成功")
	@ApiOperationSort(value = 13)
	@RequestMapping(value = "/useListInfo", method = RequestMethod.GET)
	public Object useListInfo(String projectName, PageParam<TextBookSet> pageParam) {
		IPage<TextBookSet> page = pageParam;
		page = textBookService.useListInfo(pageParam, projectName);
		return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(page).build();
	}

	@ApiOperation(value = "17.1.14 教材管理：复用信息保存 ", notes = "20000:成功")
	@ApiOperationSort(value = 14)
	@RequestMapping(value = "/userListSave", method = RequestMethod.POST)
	public Object userListSave(String projectId, String projectNewId) {
		int count = textBookService.userListSave(projectId, projectNewId);
		if (count > 0) {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data("复用历史信息成功！成功！").build();
		} else {
			return ApiResponse.builder().code(Constant.RESPONSE_CODE_31010191).data("复用历史信息失败！").build();
		}
	}

}
